home *** CD-ROM | disk | FTP | other *** search
/ Kellogg's Amérique / Kellogg's Amérique / amazonie_en_danger.swf / scripts / fl / containers / BaseScrollPane.as
Text File  |  2020-08-04  |  15KB  |  451 lines

  1. package fl.containers
  2. {
  3.    import fl.controls.ScrollBar;
  4.    import fl.controls.ScrollBarDirection;
  5.    import fl.controls.ScrollPolicy;
  6.    import fl.core.InvalidationType;
  7.    import fl.core.UIComponent;
  8.    import fl.events.ScrollEvent;
  9.    import flash.display.DisplayObject;
  10.    import flash.display.Graphics;
  11.    import flash.display.Shape;
  12.    import flash.events.MouseEvent;
  13.    import flash.geom.Rectangle;
  14.    
  15.    public class BaseScrollPane extends UIComponent
  16.    {
  17.       
  18.       protected static const SCROLL_BAR_STYLES:Object = {
  19.          "upArrowDisabledSkin":"upArrowDisabledSkin",
  20.          "upArrowDownSkin":"upArrowDownSkin",
  21.          "upArrowOverSkin":"upArrowOverSkin",
  22.          "upArrowUpSkin":"upArrowUpSkin",
  23.          "downArrowDisabledSkin":"downArrowDisabledSkin",
  24.          "downArrowDownSkin":"downArrowDownSkin",
  25.          "downArrowOverSkin":"downArrowOverSkin",
  26.          "downArrowUpSkin":"downArrowUpSkin",
  27.          "thumbDisabledSkin":"thumbDisabledSkin",
  28.          "thumbDownSkin":"thumbDownSkin",
  29.          "thumbOverSkin":"thumbOverSkin",
  30.          "thumbUpSkin":"thumbUpSkin",
  31.          "thumbIcon":"thumbIcon",
  32.          "trackDisabledSkin":"trackDisabledSkin",
  33.          "trackDownSkin":"trackDownSkin",
  34.          "trackOverSkin":"trackOverSkin",
  35.          "trackUpSkin":"trackUpSkin",
  36.          "repeatDelay":"repeatDelay",
  37.          "repeatInterval":"repeatInterval"
  38.       };
  39.       
  40.       private static var defaultStyles:Object = {
  41.          "repeatDelay":500,
  42.          "repeatInterval":35,
  43.          "skin":"ScrollPane_upSkin",
  44.          "contentPadding":0,
  45.          "disabledAlpha":0.5
  46.       };
  47.        
  48.       
  49.       protected var defaultLineScrollSize:Number = 4;
  50.       
  51.       protected var _maxHorizontalScrollPosition:Number = 0;
  52.       
  53.       protected var vScrollBar:Boolean;
  54.       
  55.       protected var disabledOverlay:Shape;
  56.       
  57.       protected var hScrollBar:Boolean;
  58.       
  59.       protected var availableWidth:Number;
  60.       
  61.       protected var _verticalPageScrollSize:Number = 0;
  62.       
  63.       protected var vOffset:Number = 0;
  64.       
  65.       protected var _verticalScrollBar:ScrollBar;
  66.       
  67.       protected var useFixedHorizontalScrolling:Boolean = false;
  68.       
  69.       protected var contentWidth:Number = 0;
  70.       
  71.       protected var contentHeight:Number = 0;
  72.       
  73.       protected var _horizontalPageScrollSize:Number = 0;
  74.       
  75.       protected var background:DisplayObject;
  76.       
  77.       protected var _useBitmpScrolling:Boolean = false;
  78.       
  79.       protected var contentPadding:Number = 0;
  80.       
  81.       protected var availableHeight:Number;
  82.       
  83.       protected var _horizontalScrollBar:ScrollBar;
  84.       
  85.       protected var contentScrollRect:Rectangle;
  86.       
  87.       protected var _horizontalScrollPolicy:String;
  88.       
  89.       protected var _verticalScrollPolicy:String;
  90.       
  91.       public function BaseScrollPane()
  92.       {
  93.          contentWidth = 0;
  94.          contentHeight = 0;
  95.          contentPadding = 0;
  96.          vOffset = 0;
  97.          _maxHorizontalScrollPosition = 0;
  98.          _horizontalPageScrollSize = 0;
  99.          _verticalPageScrollSize = 0;
  100.          defaultLineScrollSize = 4;
  101.          useFixedHorizontalScrolling = false;
  102.          _useBitmpScrolling = false;
  103.          super();
  104.       }
  105.       
  106.       public static function getStyleDefinition() : Object
  107.       {
  108.          return mergeStyles(defaultStyles,ScrollBar.getStyleDefinition());
  109.       }
  110.       
  111.       protected function handleWheel(param1:MouseEvent) : void
  112.       {
  113.          if(!enabled || !_verticalScrollBar.visible || contentHeight <= availableHeight)
  114.          {
  115.             return;
  116.          }
  117.          _verticalScrollBar.scrollPosition -= param1.delta * verticalLineScrollSize;
  118.          setVerticalScrollPosition(_verticalScrollBar.scrollPosition);
  119.          dispatchEvent(new ScrollEvent(ScrollBarDirection.VERTICAL,param1.delta,horizontalScrollPosition));
  120.       }
  121.       
  122.       public function get verticalScrollPosition() : Number
  123.       {
  124.          return _verticalScrollBar.scrollPosition;
  125.       }
  126.       
  127.       protected function drawDisabledOverlay() : void
  128.       {
  129.          if(enabled)
  130.          {
  131.             if(contains(disabledOverlay))
  132.             {
  133.                removeChild(disabledOverlay);
  134.             }
  135.          }
  136.          else
  137.          {
  138.             disabledOverlay.x = disabledOverlay.y = contentPadding;
  139.             disabledOverlay.width = availableWidth;
  140.             disabledOverlay.height = availableHeight;
  141.             disabledOverlay.alpha = getStyleValue("disabledAlpha") as Number;
  142.             addChild(disabledOverlay);
  143.          }
  144.       }
  145.       
  146.       public function set verticalScrollPosition(param1:Number) : void
  147.       {
  148.          drawNow();
  149.          _verticalScrollBar.scrollPosition = param1;
  150.          setVerticalScrollPosition(_verticalScrollBar.scrollPosition,false);
  151.       }
  152.       
  153.       protected function setContentSize(param1:Number, param2:Number) : void
  154.       {
  155.          if((contentWidth == param1 || useFixedHorizontalScrolling) && contentHeight == param2)
  156.          {
  157.             return;
  158.          }
  159.          contentWidth = param1;
  160.          contentHeight = param2;
  161.          invalidate(InvalidationType.SIZE);
  162.       }
  163.       
  164.       public function get horizontalScrollPosition() : Number
  165.       {
  166.          return _horizontalScrollBar.scrollPosition;
  167.       }
  168.       
  169.       public function get horizontalScrollBar() : ScrollBar
  170.       {
  171.          return _horizontalScrollBar;
  172.       }
  173.       
  174.       override public function set enabled(param1:Boolean) : void
  175.       {
  176.          if(enabled == param1)
  177.          {
  178.             return;
  179.          }
  180.          _verticalScrollBar.enabled = param1;
  181.          _horizontalScrollBar.enabled = param1;
  182.          super.enabled = param1;
  183.       }
  184.       
  185.       public function get verticalLineScrollSize() : Number
  186.       {
  187.          return _verticalScrollBar.lineScrollSize;
  188.       }
  189.       
  190.       public function get horizontalScrollPolicy() : String
  191.       {
  192.          return _horizontalScrollPolicy;
  193.       }
  194.       
  195.       protected function calculateAvailableSize() : void
  196.       {
  197.          var _loc1_:Number = NaN;
  198.          var _loc2_:Number = NaN;
  199.          var _loc3_:Number = NaN;
  200.          var _loc4_:Number = NaN;
  201.          var _loc5_:Number = NaN;
  202.          _loc1_ = ScrollBar.WIDTH;
  203.          _loc2_ = contentPadding = Number(getStyleValue("contentPadding"));
  204.          _loc3_ = height - 2 * _loc2_ - vOffset;
  205.          vScrollBar = _verticalScrollPolicy == ScrollPolicy.ON || _verticalScrollPolicy == ScrollPolicy.AUTO && contentHeight > _loc3_;
  206.          _loc4_ = width - (!!vScrollBar ? _loc1_ : 0) - 2 * _loc2_;
  207.          _loc5_ = !!useFixedHorizontalScrolling ? Number(_maxHorizontalScrollPosition) : Number(contentWidth - _loc4_);
  208.          hScrollBar = _horizontalScrollPolicy == ScrollPolicy.ON || _horizontalScrollPolicy == ScrollPolicy.AUTO && _loc5_ > 0;
  209.          if(hScrollBar)
  210.          {
  211.             _loc3_ -= _loc1_;
  212.          }
  213.          if(hScrollBar && !vScrollBar && _verticalScrollPolicy == ScrollPolicy.AUTO && contentHeight > _loc3_)
  214.          {
  215.             vScrollBar = true;
  216.             _loc4_ -= _loc1_;
  217.          }
  218.          availableHeight = _loc3_ + vOffset;
  219.          availableWidth = _loc4_;
  220.       }
  221.       
  222.       public function get maxVerticalScrollPosition() : Number
  223.       {
  224.          drawNow();
  225.          return Math.max(0,contentHeight - availableHeight);
  226.       }
  227.       
  228.       public function set horizontalScrollPosition(param1:Number) : void
  229.       {
  230.          drawNow();
  231.          _horizontalScrollBar.scrollPosition = param1;
  232.          setHorizontalScrollPosition(_horizontalScrollBar.scrollPosition,false);
  233.       }
  234.       
  235.       public function get horizontalLineScrollSize() : Number
  236.       {
  237.          return _horizontalScrollBar.lineScrollSize;
  238.       }
  239.       
  240.       public function set verticalPageScrollSize(param1:Number) : void
  241.       {
  242.          _verticalPageScrollSize = param1;
  243.          invalidate(InvalidationType.SIZE);
  244.       }
  245.       
  246.       public function get verticalScrollPolicy() : String
  247.       {
  248.          return _verticalScrollPolicy;
  249.       }
  250.       
  251.       protected function setHorizontalScrollPosition(param1:Number, param2:Boolean = false) : void
  252.       {
  253.       }
  254.       
  255.       public function get useBitmapScrolling() : Boolean
  256.       {
  257.          return _useBitmpScrolling;
  258.       }
  259.       
  260.       protected function handleScroll(param1:ScrollEvent) : void
  261.       {
  262.          if(param1.target == _verticalScrollBar)
  263.          {
  264.             setVerticalScrollPosition(param1.position);
  265.          }
  266.          else
  267.          {
  268.             setHorizontalScrollPosition(param1.position);
  269.          }
  270.       }
  271.       
  272.       public function set verticalLineScrollSize(param1:Number) : void
  273.       {
  274.          _verticalScrollBar.lineScrollSize = param1;
  275.       }
  276.       
  277.       public function get verticalScrollBar() : ScrollBar
  278.       {
  279.          return _verticalScrollBar;
  280.       }
  281.       
  282.       protected function setVerticalScrollPosition(param1:Number, param2:Boolean = false) : void
  283.       {
  284.       }
  285.       
  286.       public function set horizontalPageScrollSize(param1:Number) : void
  287.       {
  288.          _horizontalPageScrollSize = param1;
  289.          invalidate(InvalidationType.SIZE);
  290.       }
  291.       
  292.       override protected function draw() : void
  293.       {
  294.          if(isInvalid(InvalidationType.STYLES))
  295.          {
  296.             setStyles();
  297.             drawBackground();
  298.             if(contentPadding != getStyleValue("contentPadding"))
  299.             {
  300.                invalidate(InvalidationType.SIZE,false);
  301.             }
  302.          }
  303.          if(isInvalid(InvalidationType.SIZE,InvalidationType.STATE))
  304.          {
  305.             drawLayout();
  306.          }
  307.          updateChildren();
  308.          super.draw();
  309.       }
  310.       
  311.       public function set horizontalScrollPolicy(param1:String) : void
  312.       {
  313.          _horizontalScrollPolicy = param1;
  314.          invalidate(InvalidationType.SIZE);
  315.       }
  316.       
  317.       override protected function configUI() : void
  318.       {
  319.          var _loc1_:Graphics = null;
  320.          super.configUI();
  321.          contentScrollRect = new Rectangle(0,0,85,85);
  322.          _verticalScrollBar = new ScrollBar();
  323.          _verticalScrollBar.addEventListener(ScrollEvent.SCROLL,handleScroll,false,0,true);
  324.          _verticalScrollBar.visible = false;
  325.          _verticalScrollBar.lineScrollSize = defaultLineScrollSize;
  326.          addChild(_verticalScrollBar);
  327.          copyStylesToChild(_verticalScrollBar,SCROLL_BAR_STYLES);
  328.          _horizontalScrollBar = new ScrollBar();
  329.          _horizontalScrollBar.direction = ScrollBarDirection.HORIZONTAL;
  330.          _horizontalScrollBar.addEventListener(ScrollEvent.SCROLL,handleScroll,false,0,true);
  331.          _horizontalScrollBar.visible = false;
  332.          _horizontalScrollBar.lineScrollSize = defaultLineScrollSize;
  333.          addChild(_horizontalScrollBar);
  334.          copyStylesToChild(_horizontalScrollBar,SCROLL_BAR_STYLES);
  335.          disabledOverlay = new Shape();
  336.          _loc1_ = disabledOverlay.graphics;
  337.          _loc1_.beginFill(16777215);
  338.          _loc1_.drawRect(0,0,width,height);
  339.          _loc1_.endFill();
  340.          addEventListener(MouseEvent.MOUSE_WHEEL,handleWheel,false,0,true);
  341.       }
  342.       
  343.       protected function calculateContentWidth() : void
  344.       {
  345.       }
  346.       
  347.       public function get verticalPageScrollSize() : Number
  348.       {
  349.          if(isNaN(availableHeight))
  350.          {
  351.             drawNow();
  352.          }
  353.          return _verticalPageScrollSize == 0 && !isNaN(availableHeight) ? Number(availableHeight) : Number(_verticalPageScrollSize);
  354.       }
  355.       
  356.       protected function drawLayout() : void
  357.       {
  358.          calculateAvailableSize();
  359.          calculateContentWidth();
  360.          background.width = width;
  361.          background.height = height;
  362.          if(vScrollBar)
  363.          {
  364.             _verticalScrollBar.visible = true;
  365.             _verticalScrollBar.x = width - ScrollBar.WIDTH - contentPadding;
  366.             _verticalScrollBar.y = contentPadding;
  367.             _verticalScrollBar.height = availableHeight;
  368.          }
  369.          else
  370.          {
  371.             _verticalScrollBar.visible = false;
  372.          }
  373.          _verticalScrollBar.setScrollProperties(availableHeight,0,contentHeight - availableHeight,verticalPageScrollSize);
  374.          setVerticalScrollPosition(_verticalScrollBar.scrollPosition,false);
  375.          if(hScrollBar)
  376.          {
  377.             _horizontalScrollBar.visible = true;
  378.             _horizontalScrollBar.x = contentPadding;
  379.             _horizontalScrollBar.y = height - ScrollBar.WIDTH - contentPadding;
  380.             _horizontalScrollBar.width = availableWidth;
  381.          }
  382.          else
  383.          {
  384.             _horizontalScrollBar.visible = false;
  385.          }
  386.          _horizontalScrollBar.setScrollProperties(availableWidth,0,!!useFixedHorizontalScrolling ? Number(_maxHorizontalScrollPosition) : Number(contentWidth - availableWidth),horizontalPageScrollSize);
  387.          setHorizontalScrollPosition(_horizontalScrollBar.scrollPosition,false);
  388.          drawDisabledOverlay();
  389.       }
  390.       
  391.       protected function drawBackground() : void
  392.       {
  393.          var _loc1_:DisplayObject = null;
  394.          _loc1_ = background;
  395.          background = getDisplayObjectInstance(getStyleValue("skin"));
  396.          background.width = width;
  397.          background.height = height;
  398.          addChildAt(background,0);
  399.          if(_loc1_ != null && _loc1_ != background)
  400.          {
  401.             removeChild(_loc1_);
  402.          }
  403.       }
  404.       
  405.       public function set horizontalLineScrollSize(param1:Number) : void
  406.       {
  407.          _horizontalScrollBar.lineScrollSize = param1;
  408.       }
  409.       
  410.       public function get horizontalPageScrollSize() : Number
  411.       {
  412.          if(isNaN(availableWidth))
  413.          {
  414.             drawNow();
  415.          }
  416.          return _horizontalPageScrollSize == 0 && !isNaN(availableWidth) ? Number(availableWidth) : Number(_horizontalPageScrollSize);
  417.       }
  418.       
  419.       public function get maxHorizontalScrollPosition() : Number
  420.       {
  421.          drawNow();
  422.          return Math.max(0,contentWidth - availableWidth);
  423.       }
  424.       
  425.       protected function setStyles() : void
  426.       {
  427.          copyStylesToChild(_verticalScrollBar,SCROLL_BAR_STYLES);
  428.          copyStylesToChild(_horizontalScrollBar,SCROLL_BAR_STYLES);
  429.       }
  430.       
  431.       protected function updateChildren() : void
  432.       {
  433.          _verticalScrollBar.enabled = _horizontalScrollBar.enabled = enabled;
  434.          _verticalScrollBar.drawNow();
  435.          _horizontalScrollBar.drawNow();
  436.       }
  437.       
  438.       public function set verticalScrollPolicy(param1:String) : void
  439.       {
  440.          _verticalScrollPolicy = param1;
  441.          invalidate(InvalidationType.SIZE);
  442.       }
  443.       
  444.       public function set useBitmapScrolling(param1:Boolean) : void
  445.       {
  446.          _useBitmpScrolling = param1;
  447.          invalidate(InvalidationType.STATE);
  448.       }
  449.    }
  450. }
  451.